//
//  VideoPlayerObserverType.swift
//  VideoPlayer
//
//  Created by JY_NEW on 2021/10/13.
//

import Foundation
import FXEvent

/// 用于观察VideoPlayerManager的相关操作通知，统一管理VideoPlayerManager的事件分发
public protocol VideoPlayerManagerObserverType {
    /// 播放状态改变
    var status: FXEvent<VideoPlayerStatus> { get }
    /// 网络状态改变
    var networkStatus: FXEvent<VideoPlayerNetworkStatus> { get }
    
    /// 全屏状态改变
    var fullScreen: FXEvent<Bool> { get }
    /// 自动横竖屏改变
    var shouldAutorotate: FXEvent<Bool> { get }
    
    /// 播放速率改变
    var rate: FXEvent<Float> { get }
    /// 播放声音大小改变
    var volume: FXEvent<Float> { get }
    
    /// 当前播放时间改变（这个太频繁了）
//    var currentTime: FXEvent<TimeInterval> { get }
    /// 视频长度改变
    var duration: FXEvent<TimeInterval> { get }
    /// 可播放长度改变
    var playableDuration: FXEvent<TimeInterval> { get }
    
    /// 视频显示模式改变
    var videoGravity: FXEvent<VideoPlayerGravity> { get }
    
    /// 播放链接改变
    var url: FXEvent<URL?> { get }
}
/// 用于观察layerManager的相关操作通知，统一管理layerManager的事件分发
public protocol VideoPlayerLayerManagerObserverType {
    /// 控制层锁定状态改变
    var controlLocked: FXEvent<Bool> { get }
    /// 浮层状态改变
    var layerStatus: FXEvent<VideoPlayerLayerType> { get }
    
    /// 单击
    var singleTap: FXEvent<UITapGestureRecognizer> { get }
    /// 双击
    var doubleTap: FXEvent<UITapGestureRecognizer> { get }
    /// 长按
    var longPress: FXEvent<UILongPressGestureRecognizer> { get }
    /// 拖动
    var drag: FXEvent<VideoPlayerLayerDragInfo> { get }
}
/// 拖动信息
public class VideoPlayerLayerDragInfo: NSObject {
    /// 拖动方向(初始)
    public let direction: UISwipeGestureRecognizer.Direction
    /// 偏移值(相对初始方向)
    public let offset: CGFloat
    /// 触发点
    public let location: CGPoint
    /// 触发状态
    public let state: UIGestureRecognizer.State
    public init(direction: UISwipeGestureRecognizer.Direction, location: CGPoint, offset: CGFloat, state: UIGestureRecognizer.State) {
        self.direction = direction
        self.location = location
        self.offset = offset
        self.state = state
        super.init()
    }
    /// 拖动方向(实时)
    public var currentDirection: UISwipeGestureRecognizer.Direction {
        switch self.direction {
        case .left: return self.offset > 0 ? .left : .right
        case .right: return self.offset > 0 ? .right : .left
        case .up: return self.offset > 0 ? .up : .down
        case .down: return self.offset > 0 ? .down : .up
        default: return self.direction
        }
    }
    /// 偏移值(相对于实时方向)
    public var currentOffset: CGFloat {
        return abs(self.offset)
    }
}
